//
//  MyTabBarController.m
//  微博
//
//  Created by zxy on 2018/12/29.
//  Copyright © 2018 zxy. All rights reserved.
//

#import "MyTabBarController.h"
#import "MainTableViewController.h"
#import "XMGMessageController.h"
#import "XMGReleaseController.h"
#import "XMGSquareController.h"
#import "XMGMeController.h"
#import "MyTabBar.h"
#import "ComposeViewController.h"
@interface MyTabBarController ()

@end

@implementation MyTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addChildCtl];
}

-(void)addChildCtl{
    [self childCtl:[[MainTableViewController alloc]init] title:@"首页" normalImageName:@"tabbar_home" selectedImageName:@"tabbar_home_highlighted"];
    [self childCtl:[[XMGMessageController alloc]init] title:@"消息" normalImageName:@"tabbar_message_center" selectedImageName:@"tabbar_message_center_highlighted"];
    [self childCtl:[[XMGReleaseController alloc]init] title:@"" normalImageName:@"" selectedImageName:@""];
    [self childCtl:[[XMGSquareController alloc]init] title:@"广场" normalImageName:@"tabbar_discover" selectedImageName:@"tabbar_discover_highlighted"];
    [self childCtl:[[XMGMeController alloc]init] title:@"我" normalImageName:@"tabbar_profile" selectedImageName:@"tabbar_profile_highlighted"];
    
    //设置tabBar
    //系统tabBar为只读属性，要更改需用KVC方式
    [self setValue:[[MyTabBar alloc]init] forKey:@"tabBar"];//KVC方式
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(releaseBtnClick) name:XMGReleaseButtonClickNoticationName object:nil];
}

-(void)childCtl:(UIViewController *)childCtl title:(NSString *)title normalImageName:(NSString *)normalImageName selectedImageName:(NSString *)selectedImageName{
    UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:childCtl];
    nav.navigationBarHidden=YES;
    if(normalImageName.length || selectedImageName.length){
        childCtl.tabBarItem=[[UITabBarItem alloc]initWithTitle:title image:[[UIImage imageNamed:normalImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    }
    [childCtl.tabBarItem setTitleTextAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12],NSForegroundColorAttributeName: [UIColor cz_colorWithHex:0x2299ee]} forState:UIControlStateSelected];
    [self addChildViewController:nav];
}

-(void)releaseBtnClick{
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:[[ComposeViewController alloc]init]];
    [self presentViewController:nav animated:YES completion:nil];
}

@end
